<?php

class SiteController extends Controller
{
	public function actions()
	{
		return array(
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
			),
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}

	public function actionIndex()
    {
		$this->render('index');
	}

	public function actionError()
	{
		if($error=Yii::app()->errorHandler->error)
		{
			if(Yii::app()->request->isAjaxRequest)
				echo $error['message'];
			else
				$this->render('error', $error);
		}
	}

	public function actionLogin()
	{
		$model = new Admin;

		if(isset($_POST['Admin']))
		{
			$model->attributes = $_POST['Admin'];
			if($model->login()){
                $this->redirect($this->createUrl('admin/index'));
            }
            else{
                $this->redirect(Yii::app()->homeUrl);
            }
		}
	}

    public function actionFeedback()
    {
        $model = new Feedback;

        $model->text = $_POST['text'];
        $model->username = Yii::app()->user->name;
        $model->date = date('Y-m-d H:i:s');

        $model->insert();
    }
}